<%--
  Created by IntelliJ IDEA.
  User: 吴慧跃
  Date: 2022/5/16
  Time: 10:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>添加</title>
    <link href="/static/css/bootstrap.css" rel="stylesheet">
    <script type="text/javascript" src="/static/js/jquery-3.2.1.js"></script>
    <script src="/static/js/echarts.js"></script>
</head>
<body>
<div class="container">
    <form method="post">
        <input type="hidden" name="uid" value="${uid}"><br>
        场馆：<select name="vid">
        <option value="">--请选择--</option>
    </select> <br>
        项目类型：<select name="tid">
        <option value="">--请选择--</option>
    </select> <br>
        场地：<select name="pid">
        <option value="">--请选择--</option>
    </select> <br>
        <div id="div1">
            <span>
                开始时间：<input type="text" name="detailList[0].startTime">
            结束时间：<input type="text" name="detailList[0].endTime">
            单价：<input type="text" name="detailList[0].price">
            <button type="button" onclick="munes(this,0)">-</button><br>
            </span>


        </div>
        <button type="button" onclick="add()">新增</button>
        <br>
        <input type="button" value="保存" style="width: 200px;color: #c82333" onclick="addForm()">

    </form>
</div>
<script>
    function addForm() {
        $.post("/manage/add",$("form").serialize(),function (map) {
            if (map.error!=""){
                alert(map.error);
            }else {
                alert(map.success);
                location="/manage/list";
            }
        });
    }
    function munes(obj,idx) {
        if (idx<i){
            alert("从最后一条开始删");
            return;
        }
        $(obj).parent().remove();
        i--;
    }
    var i=0;
    function add() {
        i++;
        $("#div1").append('<span> ' +
            '开始时间：<input type="text" name="detailList['+i+'].startTime"> ' +
            '结束时间：<input type="text" name="detailList['+i+'].endTime"> ' +
            '单价：<input type="text" name="detailList['+i+'].price"> ' +
            '<button type="button" onclick="munes(this,'+i+')">-</button><br>' +
            '</span>');
    }
    $(function () {
        $.get("/manage/getVid",function (list) {
            for (var i in list){
                $('[name="vid"]').append('<option value="'+list[i].vid+'">'+list[i].vname+'</option>');
            }
            $('[name="vid"]').val(${vo.vid});
        });
        $.get("/manage/getTid",function (list) {
            for (var i in list){
                $('[name="tid"]').append('<option value="'+list[i].tid+'">'+list[i].tname+'</option>');
            }
            $('[name="tid"]').val(${vo.tid});
        });
        $.get("/manage/getPid",function (list) {
            for (var i in list){
                $('[name="pid"]').append('<option value="'+list[i].pid+'">'+list[i].pname+'</option>');
            }
            $('[name="pid"]').val(${vo.pid});
        });
    })
</script>
</body>
</html>
